import Vue from 'vue'
import VueRouter from 'vue-router'
import Live_Broadcast from '../views/Live_Broadcast'
import store from '../store'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: "Login",
    component: () => import('../views/Login')
  },
  {
    path:'/live_broadcast/:id',
    name:"Live_Broadcast",
    component:Live_Broadcast
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// console.log(store.state.getAuth.filterList);
// console.log(localStorage.getItem("token"));

router.beforeEach((to, from, next) => {
  let token=localStorage.getItem("token")
  if(token){
    if(store.state.getAuth.filterList.length===0){
      store.commit("getAuth/filterAuth",localStorage.getItem('user'))
    }else{
      console.log(111);
      
      next()
    }
  }else{
    if(to.path==='/login'){
      next()
    }else{
      next({path:"/login"})
    }
  }
})

export default router
